package com.itwn.portal.test;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootTest
public class App {
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Test
    public void test() {
        // 加密
        String encode = passwordEncoder.encode("123456");
        // $2a$10$mAZn5eeHpIkw5OGuiw3O..sFUztpywlfnm35EuOkRhthi1XBhYLEC
        // $2a$10$ZGO5R1A3SXylguSCEeIx8.KJa/.fkFfcW9jN4xJ7bbtpNDVkzBsy2
        System.out.println("encode = " + encode);

        // 校验
        boolean matches = passwordEncoder.matches("123456", "$2a$10$ZGO5R1A3SXylguSCEeIx8.KJa/.fkFfcW9jN4xJ7bbtpNDVkzBsy2");
        System.out.println("matches = " + matches);
    }
}
